﻿namespace TestIndexChart
{
    using IndexChart.Graph;
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using ZedGraph;

    public partial class Form4 : UserControl
    {
        

        StockPointList datas;
        StockPtDataSource ds = new StockPtDataSource();
        int i = 0;
        Timer timer;

        

        

        public Form4()
        {
            InitializeComponent();

            List<ZedGraph.Tuple<DateTime, DateTime>> _timespans = new List<ZedGraph.Tuple<DateTime,DateTime>>();
            _timespans.Add(new ZedGraph.Tuple<DateTime,DateTime>(new DateTime(2010,3,13,9,30,0),new DateTime(2010,3,13,10,36,0)));
            //_timespans.Add(new ZedGraph.Tuple<DateTime,DateTime>(new DateTime(2010,3,13,13,0,0),new DateTime(2010,3,13,14,0,0)));
            //_timespans.Add(new ZedGraph.Tuple<DateTime, DateTime>(new DateTime(2010, 3, 13, 18, 0, 0), new DateTime(2010, 3, 13, 22, 0, 0)));
            this.ucPriceChart1.DrawDefaultMinuteChart(new ZedGraph.Tuple<DateTime, DateTime>(new DateTime(2010, 3, 13, 9, 30, 0), new DateTime(2010, 3, 13, 10, 30, 0)));
            this.ucPriceChart1.DataSource = ds;
            this.ucPriceChart1.Displayname = "泰科集团";

            datas = DataGenerator.GenerateRedomSecondData(20100313,930,0,0 ,3000);

               this.ucPriceChart1.Chart.Draw();

            timer = new Timer();
            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = 500;
            timer.Start();
        }

        

        

        void timer_Tick(object sender, EventArgs e)
        {
            if (i == 0)
            {
                var data = (datas[0] as StockPt).Open;
                this.ucPriceChart1.UpdateMinuteChartDataRange(300, 0, 600);
            }

            if (i == 2000)
            {
                timer.Dispose();
                return;
            }
            i++;
            //if( (datas[i] as StockPt).
            ds.AddPoints(datas[i] as StockPt);
            this.ucPriceChart1.Chart.Draw();
        }

        
    }
}